package com.yfp.operation.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.operation.domain.DeviceCurrentComboPlanRoadDO;
import com.yfp.operation.domain.MachineDamageDetailDO;
import com.yfp.operation.domain.vo.ComboSaleDataVO;
import com.yfp.operation.mapper.MachineDamageDetailMapper;
import com.yfp.operation.service.MachineDamageDetailService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @description 针对表【machine_damage_detail】的数据库操作Service实现
 * @createDate 2024-04-25 10:01:12
 */
@Service
public class MachineDamageDetailServiceImpl extends ServiceImpl<MachineDamageDetailMapper, MachineDamageDetailDO> implements MachineDamageDetailService {

    @Resource
    private MachineDamageDetailMapper machineDamageDetailMapper;

    /**
     * 报损数据提交
     *
     * @param damageDTOS
     * @return
     */
    @Transactional
    @Override
    public Boolean damageHandle(List<DeviceCurrentComboPlanRoadDO> damageDTOS) {
        DateTime date = DateUtil.date();

        List<MachineDamageDetailDO> collect = damageDTOS.stream().map(item -> {
            MachineDamageDetailDO machineDamageDetailDO = new MachineDamageDetailDO();
            machineDamageDetailDO.setMachineId(item.getMachineId());
            machineDamageDetailDO.setComboId(item.getComboId());
            machineDamageDetailDO.setRoadNo(item.getRoadNumber());
            machineDamageDetailDO.setReportNum(Integer.valueOf(item.getComboNum()));
            machineDamageDetailDO.setCreateTime(date);
            machineDamageDetailDO.setUpdateTime(date);
            return machineDamageDetailDO;
        }).collect(Collectors.toList());

        return this.saveBatch(collect);
    }

    @Override
    public Integer getReportNum(String machineId) {
        return machineDamageDetailMapper.getReportNum(machineId);
    }

    @Override
    public List<MachineDamageDetailDO> lossDate(List<String> machineIds, Date startTime, Date endTime) {
        return machineDamageDetailMapper.lossDate(machineIds, startTime, endTime);
    }

    @Override
    public List<ComboSaleDataVO> lossNum(List<ComboSaleDataVO> lossDateList) {
        return machineDamageDetailMapper.lossNum(lossDateList);
    }
}




